//
//  FourTableViewCell.m
//  fp
//
//  Created by xingshuai on 2020/11/10.
//

#import "FourTableViewCell.h"

#import "XATextField.h"

@interface FourTableViewCell () <XATextFieldDelegate>

@property (nonatomic, strong) UILabel *topTitle;         // 标题
@property (nonatomic, strong) XATextField *textField;    // 联系方式

@end

@implementation FourTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView  {
    static NSString *identifier = @"XAFeedCallCellID";
    id cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self creatViewUI];
    }
    return self;
}

-(void)creatViewUI {
    self.topTitle = [[UILabel alloc]init];
    self.topTitle.text = @"联系方式";
    self.topTitle.textColor = [UIColor colorWithHexString:@"#3B3B3B"];
    self.topTitle.font = [UIFont pingFangSCWithWeight:FontWeightStyleSemibold size:20];
    [self.contentView addSubview:self.topTitle];
    [self.topTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(15);
        make.top.equalTo(self.contentView).offset(30);
        make.height.mas_equalTo(28);
    }];
    
    self.textField = [[XATextField alloc]initWithFrame:CGRectZero];
    self.textField.textColor = [UIColor colorWithHexString:@"#3B3B3B"];
    self.textField.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:@"QQ/微信/手机号码" attributes:
     @{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#AFAFAF"],
       NSFontAttributeName:[UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16]}
     ];
    self.textField.attributedPlaceholder = attrString;
    self.textField.leftPadding = 0.0;
    self.textField.limitedType = XATextFieldTypeEmail;
    //设置最大长度
    self.textField.maxLength = 20;
    self.textField.realDelegate = self;
    [self.contentView addSubview:self.textField];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.topTitle.mas_left).offset(0);
        make.right.equalTo(self.contentView).offset(-25);
        make.top.equalTo(self.topTitle.mas_bottom).offset(10);
        make.bottom.equalTo(self.contentView).offset(-20);
    }];
}

-(void)XATextFieldDidChange:(UITextField *)textField{
    if (self.didSelectContactInformationBlock) {
        self.didSelectContactInformationBlock(textField.text);
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
